<template>
  <div>
    <el-table :data="orders" style="width: 100%">
      <el-table-column prop="orderId" label="订单编号" width="100">
      </el-table-column>
      <el-table-column prop="time" label="日期" width="200">
      </el-table-column>
      <el-table-column label="配送信息">
        <el-table-column prop="username" label="买家" width="100">
        </el-table-column>
        <el-table-column prop="totalPrice" label="价格" width="100">
        </el-table-column>
        <el-table-column label="配送地址">
          <el-table-column prop="region" label="市区" width="150">
          </el-table-column>
          <el-table-column prop="street" label="街道" width="150">
          </el-table-column>
          <el-table-column prop="detailAddress" label="详细地址" width="300">
          </el-table-column>
          <el-table-column label="订单状态" width="120">

            <!-- <template slot-scope="scope">
            <el-tag  :type="tableData[0].type" effect="dark" @click="chengestatus(scope.$index, scope.row)">
              {{ tableData[0].label }}
            </el-tag>
          </template> -->
            <template slot-scope="scope">

              <span v-if="scope.row.status == 0">
                <el-button @click="updateStatus(scope.$index)" type="success" style="width: 90px" round>配送中</el-button>
              </span>
              <span v-if="scope.row.status == 1">
                <el-button @click="updateStatus(scope.$index)" type="info" style="width: 90px" round>已送达</el-button>
              </span>

            </template>
          </el-table-column>
          <el-table-column prop="date" width="150">
            <template slot-scope="scope">
              <el-button @click="save(scope.$index)">保存</el-button>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table-column>

    </el-table>
    <el-pagination
        @size-change="sizeData"
        @current-change="pageData"
        :page-sizes="[5,10,20,30,60]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="count">
      </el-pagination>
  </div>
</template>

<script>
import axios from 'axios';
export default {

  data() {
    return {
      formInline: {
        user: '',
        region: ''
      },
      searchMap: {
        page: 1,
        limit: 10,
        name: ''
      },
      merId: 1,
      orders: [],
      // items: [
      //   { type: '', label: '制作中' ,status:0},
      //   { type: 'success', label: '配送中' ,status:1},
      //   { type: 'info', label: '已完成' ,status:2}
      // ],

    }
  },
  created() {
    //在创建vue实例后触发初始化钩子函数
    this.fetchData();
  },

  methods: {
    sizeData(size){
              this.searchMap.limit=size
              this.fetchData()
            },
            pageData(page){
              this.searchMap.page=page
              this.fetchData()
            },
    fetchData() {
      //查询所有Order信息
      axios({
        url: 'http://localhost:8080/MerchatOrders/select',
        params: {
          merId:this.merId,
          page:this.searchMap.page,
          limit:this.searchMap.limit,
        },
        method: 'Post',
      }).then(response => {
        this.orders = response.data
        // console.log(response.data[0])
      })
    },

    // chengestatus(index, row) {
    //   // this.tableData[0].label = "1";
    //   console.log(1);
    //   if(this.tableData[row].item.status==0){
    //     this.tableData[0].item.status++;
    //     this.tableData[0].item=this.items[this.status];
    //     console.log("1")
    //   }else if(this.status===1){
    //     this.status++;
    //     this.item=this.items[this.status];
    //     console.log("2")
    //   }else {
    //     this.status=0;
    //     this.item=this.items[this.status];
    //     console.log("3")
    //   }
    // },
 
    updateStatus(index) {
      // console.log(index);
      switch (this.orders[index].status) {
        case '0': this.orders[index].status = '1'; break;
        case '1': this.orders[index].status = '1'; break;
        default:
          break;
      }
    },
    save(index) {
      console.log(this.orders[index])
      axios({
        url: 'http://localhost:8080/MerchatOrders/update',
        data: this.orders[index],
        method: 'Post',
      }).then(res => {
        console.log(res),
        this.$message({
          
          message: res.data.msg,
          type: 'success'
        })
        
        this.fetchData()
        //关闭弹窗
        this.dialogFormVisible = false
      })


    },
  },


}
</script>